<!-- 新建供应商 -->
<template>
  <a-drawer v-model:visible="vdata.visible" :maskClosable="false" :title="vdata.isAdd ? '新增供应商' : '回复'" width="40%">
    <a-form
      ref="formRef"
      :model="vdata.saveObject"
      layout="vertical"
      labelAlign="left"
      :rules="vdata.rules"
      :colon="false"
      :wrapper-col="{ span: 24 }"
      style="margin-top: 30px; margin-left: 20px"
    >
      <a-row>
        <a-col :span="24">
          <a-form-item label="回复描述" name="feedbackReply" :wrapper-col="{ span: 23 }">
            <a-textarea v-model:value="vdata.saveObject['feedbackReply']" placeholder="请输入回复内容" :rows="4" />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <div class="drawer-btn-center">
      <a-button :style="{ marginRight: '8px' }" style="margin-right: 8px" @click="onClose">
        <close-outlined />
        取消
      </a-button>
      <a-button type="primary" :loading="vdata.btnLoading" @click="handleOkFunc">
        <check-outlined />
        保存
      </a-button>
    </div>
  </a-drawer>
</template>
  
  <script setup lang="ts">
  // import { req,API_URL_VIRTUAGOODS_SUPPLIER_ADD,API_LITEFEEDBACK_REPLY } from '@/api/manage'
  import {$apiLiteFeedbackReply} from '@/api/fansManage/userComplain/index'
  import { reactive, ref, defineExpose, getCurrentInstance } from 'vue'
  const { $infoBox, $access } = getCurrentInstance()!.appContext.config.globalProperties
  const formRef = ref()
  
  const props = defineProps(['callBackFunc'])
  
  const vdata:any = reactive({
    isAdd: false, // 新增OR修改
    visible: false, 
    liteFeedbackId:'',
    btnLoading: true,
    saveObject: {},
    rules: {
      feedbackReply: [{ required: true, message: '通信认证参数不能为空', trigger: 'blur' },],
    },
  })
  
  function handleOkFunc() {
    formRef.value.validate().then(() => {
      vdata.btnLoading = true
      if(vdata.isAdd){  // 新增
        // req.add(API_URL_VIRTUAGOODS_SUPPLIER_ADD,vdata.saveObject).then(res=>{
        //   $infoBox.message.success('新增成功！')
        //   props.callBackFunc()
        //   onClose()
        // }).finally(()=>{
        //   vdata.btnLoading = false
        // })
      }else{  // 修改

        $apiLiteFeedbackReply({ ...vdata.saveObject,liteFeedbackId:vdata.liteFeedbackId}).then(res=>{
          $infoBox.message.success('回复成功！')
          props.callBackFunc()
          onClose()
        }).finally(()=>{
          vdata.btnLoading = false
        })
      }
    }).catch(() => {})
  }
  
  function onClose() {
    vdata.visible = false
  }
  
  function show(record) {
    console.log(record,)
    vdata.liteFeedbackId = record
    vdata.isAdd = !record
    vdata.btnLoading = false
    vdata.saveObject = {}
    if (formRef.value !== undefined) {
      formRef.value.resetFields()
    }

    if(!vdata.isAdd){ // 修改
      console.log('走到了这里444444')
      vdata.saveObject = { ...record }

    }
    vdata.visible = true
  }
  
  defineExpose({
    show,
  })
  </script>